-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compiler: factor out OVERFLOWING_LITERALS
impl
#130646
compiler: factor out OVERFLOWING_LITERALS
impl
#130646
Conversation
no functional changes should arise, just moves the lint impl details out of a very crowded file with lots of different lints in it.
no need for a weird macro when a self-explanatory `match` will do.
rustbot has assigned @michaelwoerister. Use |
I confirmed that this is mostly just moving things around. Thanks! r? compiler-errors @bors r+ rollup |
use ty::IntTy::*; | ||
use ty::UintTy::*; | ||
macro_rules! find_fit { | ||
($ty:expr, $val:expr, $negative:expr, | ||
$($type:ident => [$($utypes:expr),*] => [$($itypes:expr),*]),+) => { | ||
{ | ||
let _neg = if negative { 1 } else { 0 }; | ||
match $ty { | ||
$($type => { | ||
$(if !negative && val <= uint_ty_range($utypes).1 { | ||
return Some($utypes.name_str()) | ||
})* | ||
$(if val <= int_ty_range($itypes).1 as u128 + _neg { | ||
return Some($itypes.name_str()) | ||
})* | ||
None | ||
},)+ | ||
_ => None | ||
} | ||
} | ||
} | ||
} | ||
match t.kind() { | ||
ty::Int(i) => find_fit!(i, val, negative, | ||
I8 => [U8] => [I16, I32, I64, I128], | ||
I16 => [U16] => [I32, I64, I128], | ||
I32 => [U32] => [I64, I128], | ||
I64 => [U64] => [I128], | ||
I128 => [U128] => []), | ||
ty::Uint(u) => find_fit!(u, val, negative, | ||
U8 => [U8, U16, U32, U64, U128] => [], | ||
U16 => [U16, U32, U64, U128] => [], | ||
U32 => [U32, U64, U128] => [], | ||
U64 => [U64, U128] => [], | ||
U128 => [U128] => []), | ||
_ => None, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I at least find this kind of macro-heavy stuff extremely hard to read or understand. And I find "locating knotty bits of code in a 2000-line file" somewhat challenging, too.
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#129718 (add guarantee about remove_dir and remove_file error kinds) - rust-lang#130598 (Add recursion limit to FFI safety lint) - rust-lang#130642 (Pass the current cargo to `run-make` tests) - rust-lang#130644 (Only expect valtree consts in codegen) - rust-lang#130645 (Normalize consts in writeback when GCE is enabled) - rust-lang#130646 (compiler: factor out `OVERFLOWING_LITERALS` impl) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#130646 - workingjubilee:literally-factorize-int-lint, r=compiler-errors compiler: factor out `OVERFLOWING_LITERALS` impl This puts it into `rustc_lint/src/types/literal.rs`. It then uses the fact that it's easier to navigate the logic to identify something that can easily be factored out, as an instance of "why".
This puts it into
rustc_lint/src/types/literal.rs
. It then uses the fact that it's easier to navigate the logic to identify something that can easily be factored out, as an instance of "why".